//index.js
var con = require('../../utils/request.js')
var ui_tool = require('../../utils/uitool.js')

//获取应用实例
var app = getApp()
Page({
  data: {
    header_image:"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2528243752,1799303812&fm=11&gp=0.jpg",
    form_login:{
      account:"admin",
      password:"admin"
    },
    status_account:"",
    status_password:""
  },
  on_request_complate:function(cmd, data, status , msg){
    wx.hideToast();
    if( status == 200 )
    {      
      wx.setStorageSync('token', data.token_key);
      var user_info = wx.getStorageSync('user');
      if( !data.hasOwnProperty("nickname") ){
          //上报用户身份
          con.remote_call("user/complete_user_info",{
            nickname:user_info.nickName,
            image_head:user_info.avatarUrl,
            sex:user_info.gender == 1?'男': user_info.gender == 0?'未知':'女',
            province:user_info.province,
            city:user_info.city,
            country:user_info.country,
            code:wx.getStorageSync('code')
          }, this)
      }
      return;
      wx.redirectTo({
          url:"../coach_mana_center/main"
      })      
    }
    else
    {
      ui_tool.show_error(msg);
    }
  },  
  onLogin: function(e){
      // 正式功能
      if( this.data.form_login.account == "" ){
        this.setData({status_account:"账号不能为空"});
        return;
      }
      
      if( this.data.form_login.password == "" ){
        this.setData({status_password:"账号不能为空"});
        return;
      }
      con.remote_call("user/login",this.data.form_login, this);
      wx.showLoading({
        title:"登陆中..."
      })
      
      
  },
  onLoad: function () {
    return;
      wx.redirectTo({
          url:"../coach_mana_center/main"
      })
  },
  inputChange:function(e){
      var ids = e.target.id;
      var content = {};
      content[ids] = e.detail.value;
      this.setData(content)
  }
})
